<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 3/24/16
 * Time: 6:03 PM
 */

namespace Admin\Controller;

class ExpertLevelController extends AuthController
{

    /**
     * 专家列表
     */
    public function level_list()
    {
        $model = M('expert_level');
        $data = $model->select();
        $this->assign(['data' => $data]);
        $this->display();
    }

    /**
     * 专家编辑
     */
    public function level_edit()
    {
        $opt = I('get.action');
        if ($opt == 'edit') {
            $id = I('get.id');
            if (!empty($id)) {
                $data = array();
                $data['name'] = I('get.name');
                $data['updatetime'] = time();
                $result = M('expert_level')->where(['id' => $id])->save($data);
                if ($result) {
                    $this->ajaxReturn(1);
                } else {
                    $this->ajaxReturn(2);
                }
            }
        }
        $id = I('get.id');
        $data = M('expert_level')->where(['id' => $id])->find();
        $this->assign(['data' => $data]);
        $this->display();
    }

    protected function getMemberInfo($userid)
    {
        if (!empty($userid)) {
            $map['userid'] = $userid;
            $data = D('Member')->relation(true)->where($map)->select();
        } else {
            $data = D('Member')->relation(true)->select();
            //dump(D('Member')->getLastSql());

        }
        foreach ($data AS $k => $v) {
            $data[$k] = $v;
            $avatar = $v['member_profile']['avatar'];
            if (!is_null($avatar)) {
                $data[$k]['avatar'] = C('WEB_URL') . $avatar;
            } else {
                $data[$k]['avatar'] = C('TMPL_PARSE_STRING.__ADMIN__') . "images/thumb.jpg";
            }
            //  $data[$k]['score'] = $v['member_profile']['score'] != ''?$v['member_profile']['score']:0;
            $data[$k]['addtime'] = date('Y-m-d h:i:s', $v['addtime']);
            $data[$k]['last_login_time'] = date('Y-m-d h:i:s', $v['last_login_time']);
            // $area = getAreaFullNameFromAreaID($v['member_profile']['areaid']);
            //   $data[$k]['area'] = arr2str($area,'');
            $data[$k]['zt'] = $v['status'];
        }
        return $data;
    }
}